package com.heima.search.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.search.dtos.SearchArticleDto;
import com.heima.search.dtos.UserSearchDto;
import com.heima.search.service.ArticleSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/v1/article/search")
public class SearchController {

    @Autowired
    private ArticleSearchService articleSearchService;

    /**
     * 用户搜索
     *
     * @param userSearchDto 用户搜索的条件
     * @return 返回用户搜索结果的列表
     * @throws IOException 异常信息
     */
    @PostMapping("/search")
    public ResponseResult<SearchArticleDto> search(@RequestBody UserSearchDto userSearchDto) throws IOException {
        List<SearchArticleDto> list = articleSearchService.search(userSearchDto);
        return ResponseResult.okResult(list);
    }
}
